package com.e5.training.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.e5.training.domain.User;
import com.e5.training.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class UserEditAction extends ActionSupport implements ModelDriven<Object>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String userId;
	private User user = new User();
	@Autowired
	private UserService userService;
	
	
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		String flag = null;
//		System.out.println("==================="+userId);
		user = userService.getUser(userId);
		
//		System.out.println("----------------------");

		try
		{
			if(user != null)
			{
				flag = "success";
			}
			else
			{
				flag = "failure";
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			throw e;
		}
		return flag;
	}
	
	

//	/**
//	 * @return the userID
//	 */
//	public String getUserID() {
//		return userId;
//	}
//
//
//
//	/**
//	 * @param userID the userID to set
//	 */
//	public void setUserID(String userID) {
//		this.userId = userID;
//	}
//


	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}
	/**
	 * @return the userId
	 */
	public String getUserId() {
		return userId;
	}



	/**
	 * @param userId the userId to set
	 */
	public void setUserId(String userId) {
		this.userId = userId;
	}



	/**
	 * @param user the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}
	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return user;
	}
	
	
}
